package org.syncsoft.overalt.gui.impl.window.viewHistory;

import java.util.ArrayList;
import java.util.Collection;

import org.syncsoft.overalt.common.exception.SystemException;
import org.syncsoft.overalt.domain.document.entity.History;
import org.syncsoft.overalt.gui.api.WindowContextValue;
import org.syncsoft.overalt.gui.api.window.AbstractWindowController;

/**
 * 
 * @author tptfc
 *
 */
public class ViewHistoryWindowController extends AbstractWindowController<ViewHistoryWindow> {
	private String path;
	
	public ViewHistoryWindowController(String path) {
		setPath(path);
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.syncsoft.overalt.gui.swing.api.window.AbstractWindowController#doCreateWindow()
	 */
	@Override
	protected ViewHistoryWindow doCreateWindow() throws SystemException {
		getPath();
		ViewHistoryWindow window = new ViewHistoryWindow(this);
		
		Collection<History> histories = new ArrayList<History>();
		
		for (int i = 0 ; i < 60; i++) {
			History h = new History();
			h.setCode(i);
			
			StringBuffer buffer = new StringBuffer();
			
			for (int j = 0; j < i + 1; j++) {
				buffer.append("bla bla bla bla ");
			}
			
			h.setDescription(buffer.toString());
			h.setVersion("version_" + i);
			
			histories.add(h);
		}
		
		window.setHistories(histories);
		
		return window;
	}

	@Override
	protected void doSubmit(WindowContextValue context) throws SystemException {
		int historyCode = context.getValue("history");
		System.out.println(historyCode);
	}

	private String getPath() {
		return path;
	}

	private void setPath(String path) {
		this.path = path;
	}
}
